//
//  HYNavBaseViewController.m
//  Around
//
//  Created by 华谕 on 2017/6/14.
//  Copyright © 2017年 HUYU. All rights reserved.
//

#import "HYNavBaseViewController.h"

@interface HYNavBaseViewController ()

@end

@implementation HYNavBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];

   
    
//    [self.navigationBar setBackgroundImage:[UIImage imageWithColor:ThemeColor] forBarMetrics:(UIBarMetricsDefault)];
    [self.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]}];
//    self.navigationBar.barStyle = UIBarStyleBlack;

}


//重写pushViewController方法
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    if (self.viewControllers.count) {
        //隐藏自定义的tabbar
        viewController.hidesBottomBarWhenPushed = YES;
        [self.navigationItem setHidesBackButton:YES];
        if (animated)
        {
            //更改返回按钮
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(100, 32, 50, 20);
            [btn setImage:[UIImage imageNamed:@"backimg"] forState:UIControlStateNormal];
            //[btn setBackgroundImage:[UIImage imageNamed:@"backBtn"] forState:UIControlStateNormal]; //与上面方法效果相同
            btn.contentHorizontalAlignment = 1;
            btn.contentVerticalAlignment = 0;
            [btn addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside];
            
            UIBarButtonItem * back=[[UIBarButtonItem alloc]initWithCustomView:btn];
            viewController.navigationItem.leftBarButtonItem = back;
            viewController.navigationController.navigationBar.tintColor = [UIColor blackColor];

        }
        else
        {
            [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
            viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:nil action:nil];
        }
        
        
    }
    [super pushViewController:viewController animated:YES];
    
}

- (void)backButtonClick:(UIButton *)button {
    //self 已经是NavigationController 就不要self.navigationController
    [self popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}





@end
